<template>
  <div class="containet">
      <div class="children border-bottom" v-for="(product, index) of productList" :key="index" v-show="more(index)">
        <div class="product" @click="handleProductClick(index)">
          <div class="product-title">{{product.title}}
            <div class="product-content" v-if="product.content">{{product.content}}</div>
          </div>
          <div class="price-info">
            <div class="price" slot="price">
              ￥<em class="price-num">{{product.price}}</em>
              <span class="price-numword">起</span>
            </div>
            <span :class="{'arrow-active' : product.ticketShow}" class="iconfont arrow-icon">&#xe624;</span>
          </div>
        </div>
        <list-ticket v-show="product.ticketShow" :ticketList="product.children" />
      </div>
      <div v-if="moreShow" @click="handleMoreClick" class="product-more border-bottom">
        查看剩余产品
        <span class="iconfont more-icon">&#xe624;</span>
      </div>
  </div>
</template>

<script>
import ListTicket from './Ticket'
export default {
  name: 'ListProduct',
  props: {
    productList: {
      type: Array,
      default () {
        return []
      }
    }
  },
  data () {
    return {
      moreList: false
    }
  },
  components: {
    ListTicket
  },
  computed: {
    moreShow () {
      if (!this.moreList) {
        return this.productList.length >= 2 ? 1 : 0
      } else {
        return false
      }
    }
  },
  methods: {
    handleProductClick (n) {
      this.$set(this.productList[n], 'ticketShow', !this.productList[n].ticketShow)
    },
    more (index) {
      if (!this.moreList) {
        return index >= 2 ? 0 : 1
      } else {
        return true
      }
    },
    handleMoreClick () {
      this.moreList = true
    }
  }
}
</script>

<style lang="stylus" scoped>
  @import '~styles/mixins.styl'
  .children
    .product
      padding .2rem
      background-color #fff
      display flex
      flex-direction row
      .product-title
        margin-right .1rem
        flex 1
        min-width 0
        font-size .3rem
        line-height .48rem
        .product-content
          font-size .24rem
          color #888
          height .32rem
          line-height .32rem
          ellipsis()
      .price-info
        display flex
        align-items center
        flex-direction row
        padding 0 .1rem
        .price
          display inline-flex
          flex-direction row
          align-items baseline
          color: #ff9800
          font-size .24rem
          .price-num
            font-size .4rem
        .arrow-icon
          color #9e9e9e
          font-size .24rem
          margin-left .1rem
          transform rotate(270deg)
        .arrow-active
          transform rotate(90deg)
  .product-more
    height .8rem
    background #fff
    color #616161
    line-height .8rem
    text-align center
    display flex
    flex-direction row
    justify-content center
    .more-icon
      color #9e9e9e
      font-size .24rem
      margin-left .1rem
      transform rotate(270deg)
</style>
